package com.example.javamaday.leetcode;

import java.util.ArrayList;
import java.util.List;

public class LeetCodeTest0022 {

    public static void main(String[] args) {

        new LeetCodeTest0022().generateParenthesis(3);
    }

    private List<String> result = new ArrayList<>();

    public List<String> generateParenthesis(int n) {
        createParenthesis(0, 0, n, "");
        return result;
    }

    public void createParenthesis(int left, int right, int max, String s) {
        if (left == max && right == max) {
            result.add(s);
            return;
        }
        if (left < max) {
            createParenthesis(left + 1, right, max, s + "(");
        }
        if (right < max) {
            createParenthesis(left, right + 1, max, s + ")");
        }
    }

}
